﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using MySqlConnection;
using Framework;
using Application;

namespace Data
{
    public static class ImageData
    {
        public static VOImage GetImage2(string id)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            ImageClass img = dbCont.GetImageById(id);
            return VOMapperImage.ImageInstanceFromData(img);
        }

        public static List<VOImage> GetAllImages2()
        {
            List<VOImage> imgs = new List<VOImage>();
            DBContainer dbCont = MySqlContext.DataContext;
            List<ImageClass> allImages = dbCont.GetAllImages();
            foreach (ImageClass img in allImages)
            {
                imgs.Add(VOMapperImage.ImageInstanceFromData(img));
            }
            return imgs;
        }

        public static void InsertImage(VOImage img)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            dbCont.CreateImage(img.Title, img.Description, DateTime.Now.ToString(), img.Extension, img.Data, img.Size);
        }

        public static void UpdateImage(VOImage imgObj)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            dbCont.UpdateImage(MappingTool.CatchNull(imgObj.Id), imgObj.Title, imgObj.Description);
        }
    }
}